package com.yst.suivi.data.activities;

import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.EntityBean;

import com.yst.suivi.data.AbstractEntityBean;
import com.yst.suivi.data.contrats.Contrat;
import com.yst.suivi.data.folders.Folder;
import com.yst.suivi.data.project.Project;
import com.yst.suivi.data.project.versions.ProjectVersion;
import com.yst.suivi.data.project.versions.lot.Lot;
import com.yst.suivi.data.team.TeamRole;
import com.yst.suivi.status.StatusConstants;

/**
 * @author stolf
 * @ejb.bean name="Activity" type="CMP" cmp-version="2.x" schema="activity"
 *           local-jndi-name="ActivityBean" view-type="local" primkey-field =
 *           "id" reentrant = "True"
 * @ejb.home generate="local"
 * @ejb.persistence table-name = "activity"
 * @jboss.entity-command name = "key-generator"
 * @jboss.read-ahead eager-load-group = "most" strategy = "on-load"
 *                   page-size="25"
 * @jboss.load-group name="most"
 * @ejb.interface local-extends = "com.yst.suivi.data.util.NamedObject,
 *                javax.ejb.EJBLocalObject"
 * @ejb.finder signature="java.util.Collection
 *             findByProject(com.yst.suivi.data.project.versions.ProjectVersion
 *             prjVersion)" query="SELECT OBJECT(g) FROM activity AS g WHERE
 *             g.projectVersion=?1"
 * @ejb.finder signature="java.util.Collection
 *             findByUser(com.yst.suivi.data.user.User usr)" query="SELECT
 *             OBJECT(g) FROM activity AS g, IN (g.user) AS equipe WHERE equipe=?1 AND g.status=1"
 * 
 * @ejb.finder signature="java.util.Collection
 *             findByContratAndProject(com.yst.suivi.data.contrats.Contrat
 *             contrat, com.yst.suivi.data.project.Project prj)" query="SELECT
 *             OBJECT(g) FROM activity AS g WHERE g.contrat=?1 AND g.project=?2"
 * 
 * @ejb.finder signature="java.util.Collection
 *             findByUserAndProject(com.yst.suivi.data.user.User usr,
 *             com.yst.suivi.data.project.Project prj)" query="SELECT OBJECT(g)
 *             FROM activity AS g, IN (g.user) AS equipe  WHERE equipe=?1 AND g.project=?2 AND
 *             g.status=1"
 *             @ejb.finder signature="java.util.Collection
 *             findByLot(com.yst.suivi.data.project.versions.lot.Lot
 *             lot)" query="SELECT OBJECT(g) FROM activity AS g WHERE
 *             g.lot=?1"
 */
public abstract class ActivityBean extends AbstractEntityBean implements EntityBean
{
	/**
	 * @return
	 * @throws CreateException
	 * @ejb.create-method view-type = "local"
	 */
	public String ejbCreate() throws CreateException
	{
		setStatus(StatusConstants.IN_PROGRESS);
		return null;
	}

	public void ejbPostCreate()
	{
		// by default nothing to do
	}

	/**
	 * Return the primary key of the object
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.jdbc-type type = "VARCHAR"
	 * @jboss.sql-type type = "VARCHAR(255)"
	 */
	public abstract String getId();

	/**
	 * Fix the primary key of the object. The method should be used only by the
	 * container
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setId(String id);

	/**
	 * Return the name of the object
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 * @jboss.jdbc-type type = "VARCHAR"
	 * @jboss.sql-type type = "VARCHAR(255)"
	 */
	public abstract String getNom();

	/**
	 * Fix the name of the user. The method should be used only by the container
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setNom(String nom);

	/**
	 * Retourne la duree prevue pour l'activite
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract Float getDuree();

	/**
	 * Positionne la duree prevue pour l'activite
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setDuree(Float duree);

	/**
	 * Retourne ltemps estime pour finir la tache
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract Float getRaf();

	/**
	 * Positionne le temps estime pour finir la tache
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setRaf(Float raf);

	/**
	 * Etat de l'activite. Selon l'etat, elle peut etre plus ou moins modifiee
	 * 
	 * @ejb.interface-method view-type = "local"
	 * @ejb.persistence
	 * @jboss.load-group name="most"
	 */
	public abstract int getStatus();

	/**
	 * Positionne l'etat de l'activite
	 * 
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setStatus(int status);

	/**
	 * La methode lie l'activite a un rangement
	 * 
	 * @return
	 * @ejb.relation name="activity-folder" role-name = "ActivityFolder"
	 *               target-role-name = "ActivityFolderRole" target-multiple =
	 *               "yes" target-ejb="Folder"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "folderId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract Folder getFolder();

	/**
	 * La methode lie l'activite a un projet
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setFolder(Folder folder);
	
	/**
	 * La methode lie l'activite a lot
	 * 
	 * @return
	 * @ejb.relation name="activity-lot" role-name = "ActivityLot"
	 *               target-role-name = "ActivityLotRole" target-multiple =
	 *               "yes" target-ejb="Lot"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "lotId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract Lot getLot();

	/**
	 * La methode lie l'activite a un Lot
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setLot(Lot lot);

	/**
	 * La methode lie l'activite a un contrat (Workpackage) LE lien signifie que
	 * l'activite est facturee a un client
	 * 
	 * @return
	 * @ejb.relation name="activity-contrat" role-name = "ActivityContrat"
	 *               target-role-name = "ActivityContratRole" target-multiple =
	 *               "yes" target-ejb="Contrat"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "contratId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract Contrat getContrat();

	/**
	 * La methode lie l'activite a un projet
	 * 
	 * @param contrat
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setContrat(Contrat contrat);

	/**
	 * Retourne l'utilisateur affecte a la tache ejb.relation
	 * name="activity-user" role-name = "ActivityUser" target-role-name =
	 * "ActivityUserRole" target-multiple = "yes" target-ejb="User"
	 * jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 * "userId"
	 * 
	 * @ejb.interface-method view-type = "local"
	 * 
	 * @ejb.relation name="activity-user" role-name = "activity-userRole"
	 *               target-multiple = "yes" 
	 * @jboss.relation-mapping style = "relation-table"
	 * @jboss.relation-table table-name = "LnkActivityUser"
	 * @jboss.relation fk-column = "idUser" related-pk-field = "id"
	 * 
	 * @return User
	 */
	public abstract Collection getUser();
//	@ejb.interface-method view-type = "local"
//		 * 
//		 * @ejb.relation name="activity-user" role-name = "activity-userRole"
//		 *               target-multiple = "yes" target-role-name =
//		 *               "User-activityTargetRole" target-ejb = "User"
//		 * @jboss.relation-mapping style = "relation-table"
//		 * @jboss.relation-table table-name = "LnkActivityUser"
//		 * @jboss.relation fk-column = "idUser" related-pk-field = "id"
//		 * @jboss.target-relation fk-column = "idActivity" related-pk-field = "id"
//		 * 
	/**
	 * Positionne la liste de tous les utilisateurs qui sont affectes a la
	 * tache. La collection doit contenir des objets User.
	 * 
	 * @param users
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setUser(Collection users);

	/**
	 * La methode lie l'Activity a une version de projet
	 * 
	 * @return
	 * @ejb.relation name="activity-projetVersion" role-name =
	 *               "ActivityProjetVersion" target-role-name =
	 *               "ActivityProjetVersionRole" target-multiple = "yes"
	 *               target-ejb="ProjectVersion"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "prjVersionId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract ProjectVersion getProjectVersion();

	/**
	 * La methode lie le Activity a un projet
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setProjectVersion(ProjectVersion plf);
	
	/**
	 * La methode lie l'Activity a un role
	 * 
	 * @return
	 * @ejb.relation name="activity-teamRole" role-name =
	 *               "ActivityteamRole" target-role-name =
	 *               "ActivityteamRoleRole" target-multiple = "yes"
	 *               target-ejb="TeamRole"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "teamRoleId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract TeamRole getTeamRole();

	/**
	 * La methode lie le Activity a TeamRole
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setTeamRole(TeamRole plf);

	/**
	 * La methode lie le folder a un projet
	 * 
	 * @return
	 * @ejb.relation name="activity-projet" role-name = "ActivityProjet"
	 *               target-role-name = "ActivityProjetRole" target-multiple =
	 *               "yes" target-ejb="Project"
	 * @jboss.relation related-pk-field = "id" fk-constraint = "true" fk-column =
	 *                 "prjId"
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract Project getProject();

	/**
	 * La methode lie l'activite a un projet
	 * 
	 * @param plf
	 * @ejb.interface-method view-type = "local"
	 */
	public abstract void setProject(Project plf);
}
